package com.ocm.tourism.core.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
public class CommonItems {

   @NotNull
   @Size(max = 74)
   private String name;

   @OneToOne
   private CommonItems parentId;

   @NotNull
   @Enumerated(EnumType.STRING)
   private ItemTypes itemTypes;

   @ManyToMany(cascade = CascadeType.ALL)
   private Set<CommonItems> childs = new HashSet<CommonItems>();

   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_COMMONITEM")
   @TableGenerator(name = "GEN_COMMONITEM", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "COMMONITEM")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public CommonItems getParentId() {
      return this.parentId;
   }

   public void setParentId(CommonItems parentId) {
      this.parentId = parentId;
   }

   public Set<CommonItems> getChilds() {
      return this.childs;
   }

   public void setChilds(Set<CommonItems> childs) {
      this.childs = childs;
   }

   public ItemTypes getItemTypes() {
      return itemTypes;
   }

   public void setItemTypes(ItemTypes itemTypes) {
      this.itemTypes = itemTypes;
   }
}
